home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / menu.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  4.5 KB  |  129 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. from gettext import gettext as _
  5. import app
  6. import eventloop
  7. import tabs
  8.  
  9. def makeMenu(items):
  10.     '''Convenience function to create a list of MenuItems given on a list of
  11.     (callback, label) tuples.
  12.     '''
  13.     return [ MenuItem(callback, label) for callback, label in items ]
  14.  
  15.  
  16. class MenuItem:
  17.     """A single menu item in a context menu.
  18.  
  19.     Normally frontends should display label as the text for this menu item,
  20.     and if it's clicked on call activate().  One second case is if label is
  21.     blank, in which case a separator should be show.  Another special case is
  22.     if callback is None, in which case the label should be shown, but it
  23.     shouldn't be clickable.  
  24.     
  25.     """
  26.     
  27.     def __init__(self, callback, label):
  28.         self.label = label
  29.         self.callback = callback
  30.  
  31.     
  32.     def activate(self):
  33.         """Run this menu item's callback in the backend event loop."""
  34.         eventloop.addUrgentCall(self.callback, 'context menu callback')
  35.  
  36.  
  37.  
  38. def makeContextMenu(templateName, view, selection, clickedID):
  39.     if len(selection.currentSelection) == 1:
  40.         obj = selection.getObjects()[0]
  41.         if isinstance(obj, tabs.Tab):
  42.             obj = obj.obj
  43.         
  44.         return obj.makeContextMenu(templateName, view)
  45.     else:
  46.         type = selection.getType()
  47.         objects = selection.getObjects()
  48.         if type == 'item':
  49.             return makeMultiItemContextMenu(templateName, view, objects, clickedID)
  50.         elif type == 'playlisttab':
  51.             return makeMenu([
  52.                 (app.controller.removeCurrentPlaylist, _('Remove'))])
  53.         elif type == 'channeltab':
  54.             return makeMenu([
  55.                 (app.controller.updateCurrentFeed, _('Update Channels Now')),
  56.                 (app.controller.removeCurrentFeed, _('Remove'))])
  57.         else:
  58.             return None
  59.  
  60.  
  61. def makeMultiItemContextMenu(templateName, view, selectedItems, clickedID):
  62.     c = app.controller
  63.     watched = unwatched = downloaded = downloading = available = uploadable = 0
  64.     for i in selectedItems:
  65.         if i.getState() == 'downloading':
  66.             downloading += 1
  67.             continue
  68.         if i.isDownloaded():
  69.             if i.downloader and i.downloader.getState() == 'finished' and i.downloader.getType() == 'bittorrent':
  70.                 uploadable += 1
  71.             
  72.             downloaded += 1
  73.             if i.getSeen():
  74.                 watched += 1
  75.             else:
  76.                 unwatched += 1
  77.         i.getSeen()
  78.         available += 1
  79.     
  80.     items = []
  81.     if downloaded > 0:
  82.         items.append((None, _('%d Downloaded Items') % downloaded))
  83.         (None, None, items.append)(((lambda : c.playView(view, clickedID)), _('Play')))
  84.         items.append((c.addToNewPlaylist, _('Add to new playlist')))
  85.         if templateName in ('playlist', 'playlist-folder'):
  86.             label = _('Remove From Playlist')
  87.         else:
  88.             label = _('Remove From the Library')
  89.         items.append((c.removeCurrentItems, label))
  90.         if watched:
  91.             
  92.             def markAllUnseen():
  93.                 for item in selectedItems:
  94.                     item.markItemUnseen()
  95.                 
  96.  
  97.             items.append((markAllUnseen, _('Mark as Unwatched')))
  98.         
  99.         if unwatched:
  100.             
  101.             def markAllSeen():
  102.                 for item in selectedItems:
  103.                     item.markItemSeen()
  104.                 
  105.  
  106.             items.append((markAllSeen, _('Mark as Watched')))
  107.         
  108.     
  109.     if available > 0:
  110.         if len(items) > 0:
  111.             items.append((None, ''))
  112.         
  113.         items.append((None, _('%d Available Items') % available))
  114.         items.append((app.controller.downloadCurrentItems, _('Download')))
  115.     
  116.     if downloading:
  117.         if len(items) > 0:
  118.             items.append((None, ''))
  119.         
  120.         items.append((None, _('%d Downloading Items') % downloading))
  121.         items.append((app.controller.stopDownloadingCurrentItems, _('Cancel Download')))
  122.         items.append((app.controller.pauseDownloadingCurrentItems, _('Pause Download')))
  123.     
  124.     if uploadable > 0:
  125.         items.append((c.startUploads, _('Restart Upload')))
  126.     
  127.     return makeMenu(items)
  128.  
  129.